<?php
/**
 * Created by PhpStorm.
 * User: surface
 * Date: 2019/1/11
 * Time: 20:19
 */
namespace app\Manage\controller;
use think\Request;
use app\common\model\UserBalance as UserBalanceModel;
use app\common\controller\Manage as ManageController;

class UserBalance extends ManageController{

    public function index(Request $requst)
    {
        if($requst->isAjax()) {
            $balance_model = new UserBalanceModel();
            $input = $requst->post();
            $condition = [];
            if(!empty($input['admin_name'])) {
                $condition[] = ['manage.username', 'like', '%'.$input['admin_name'].'%'];
            }
            if(!empty($input['mobile'])) {
                $condition[] = ['user.mobile', 'like', '%'.$input['mobile'].'%'];
            }
            $field = 'log.*, user.nickname as user_name, manage.username as admin_name, FROM_UNIXTIME(log.ctime, \'%Y-%m-%d %H:%i:%s\') as date';
            $list = $balance_model->alias('log')
                    ->join('user', 'user.id = log.user_id')
                    ->join('manage', 'manage.id = log.admin_id')
                    ->where($condition)
                    ->field($field)
                    ->order('id desc')
                   ->paginate($input['limit']);
            $re['code'] = 0;
            $re['msg'] = '';
            $re['count'] = $list->total();
            $re['data'] = $list->items();
            return $re;
        } 
        return $this->fetch('index');
    }
}